package concurrency.intrinsic.locks;

import java.util.ArrayList;
import java.util.List;

public class IntrinsicLockDemo {

  List<String> messages = new ArrayList<String>();
  
  IntrinsicLockDemo()  {
    //empty
  }
  
  public void addMessage(String m) {
    synchronized(this) {
      messages.add(m);
    }
  }
  
  public String getHeadMessage() {
    String m = null;
    synchronized(this) {
      if(messages.size() > 0) {
        m = messages.get(0);
      }
    }
    return m;
  }

  public static void main(String[] args) {
    IntrinsicLockDemo ild = new IntrinsicLockDemo();
    
    //Psuedo code
    //Thread producer1(ild)
    //Thread producer2(ild)
    //Thread consumer(ild)
  }

}
